package com.libraryManage.controller;

import com.libraryManage.commons.utils.ResponseEntity;
import com.libraryManage.commons.utils.SimpleResp;
import com.libraryManage.entity.BorrowDo;
import com.libraryManage.entity.BorrowingUser;
import com.libraryManage.service.BorrowService;
import com.libraryManage.vo.BorrowVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:ZhangQing
 * @Date:2020/11/4
 */
@Api(tags={"借阅管理接口"})
@RestController
@CrossOrigin
@RequestMapping("/manage/borrow")
public class BorrowController {
    @Autowired
    private BorrowService borrowService;

    /**
     * 返回所有借阅记录
     * @return
     */
    @ApiOperation("返回所有借阅记录")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/all" , method = RequestMethod.GET)
    public ResponseEntity<List<BorrowDo>> getAllBorrow(){
        return borrowService.getAllBorrow();
    }

    /**
     * 根据借书id返回数据
     * @return
     */
    @ApiOperation("根据借书id返回数据")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "findOne/{id}" , method = RequestMethod.GET)
    public BorrowDo getBorrowById(@PathVariable("id") Integer id){
        return borrowService.getBorrowById(id);
    }

    @ApiOperation("新增借书记录")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "insert" , method = RequestMethod.POST)
    public SimpleResp insertBorrow(@RequestBody BorrowVo borrowVo){
        return borrowService.insertBorrow(borrowVo);

    }

    @ApiOperation("查询借阅信息接口")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/list" , method = RequestMethod.POST)
    public ResponseEntity<List<BorrowVo>> getLit(@RequestBody BorrowVo vo){
        return borrowService.getList(vo);
    }

    @ApiOperation("获取未处理预约借阅列表")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/borrowingUser" , method = RequestMethod.POST)
    public ResponseEntity<List<BorrowingUser>> getBorrowing(BorrowingUser borrowingUser){

        return borrowService.getBorrowingUser(borrowingUser);

    }

    @ApiOperation("处理预约借阅")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/updateBorrowingState" , method = RequestMethod.GET)
    public ResponseEntity<List<BorrowingUser>> updateBorrowingState(int userId, int bookId,int borrowingState){

        return borrowService.updateBorrowingState(userId,bookId,borrowingState);

    }

}
